<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			var firstUniqChar = function(s) {
				let arr = [...s];
				//删除重复元素
				for (let i = 0; i < arr.length; i++) {
					if (arr[i] == undefined) {
						continue
					}
					//定义个bool，主要是为了删除第一个重复的
					let f = false;
					for (let j = i + 1; j < arr.length; j++) {
						if (arr[i] == arr[j]) {
							f = true;
							delete arr[j];
						}
					}
					if(f){
						delete arr[i];
					}
				}
				//目前的数组也许是undefined undefined xxx,找到第一个值。
				for (let i = 0; i < arr.length; i++) {
					if(arr[i]){
						return i;
					}
				}
				//如果所有都是undefined,返回-1
				return -1;
			};
			console.log(firstUniqChar("loveleetcode"));
		</script>
	</body>
</html>
